﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using WebBrowserTest.AnalyzeResults;

namespace WebBrowserTest.Analyzers
{
    public class DmozAnalyzer : AbstractAnalyzer
    {
        public string LookupExpression { get; set; }
        public DmozAnalyzer()
        {
            _lookupExpr = @"Open Directory Sites[^\(]+\(.+of (\d+)\)|(No) <b><a href=http://dmoz.org/>Open Directory Project</a></b> results";
        }

        public override AbstractAnalyzeResult GetAnalyseResult(string html, string url)
        {

            var matches = Regex.Matches(html, _lookupExpr);
            var oDirSitesCount = 0;
            var cacheDate = new DateTime();
            for (var i = 0; i < matches.Count; i++)
            {
                var oDirSitesString = matches[i].Groups[1].Value;
                if (int.TryParse(oDirSitesString, out oDirSitesCount))
                {
                }

                break;
            }
            return new DefaultResult() { Value = oDirSitesCount, DomainName = url, Date = DateTime.Now };
        }
    }
}
